import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;


class P10933_39643 {

	public static void main(String[] args) {
		while (true) {
			int t = Integer.parseInt(readLn());
			if (t == 0) break;
			
			Team10933[] array = new Team10933[t];
			HashMap<String, Integer> teamIndex = new HashMap<String, Integer>();
			for (int k = 0; k < t; k++) {
				array[k] = new Team10933();
				array[k].name = readLn();
				teamIndex.put(array[k].name, k);
			}
			
			int m = Integer.parseInt(readLn());
			
			for (int k = 0; k < m; k++) {
				StringTokenizer st = new StringTokenizer(readLn(), ":");
				
				StringTokenizer teamsTokens = new StringTokenizer(st.nextToken(), "-");
				
				Team10933 team1 = array[teamIndex.get(teamsTokens.nextToken())];
				Team10933 team2 = array[teamIndex.get(teamsTokens.nextToken())];
				
				StringTokenizer setsTokens = new StringTokenizer(st.nextToken());
				
//				int[][] sets = new int[setsTokens.countTokens()][2];
				
				int length = setsTokens.countTokens();
				
				int sets1Won = 0;
				int sets2Won = 0;
				int sets1Lost = 0;
				int sets2Lost = 0;
				
				for (int i = 0; i < length; i++) {
					StringTokenizer pointsTokens = new StringTokenizer(setsTokens.nextToken(), "-");
//					sets[i][0] = Integer.parseInt(pointsTokens.nextToken());
//					sets[i][1] = Integer.parseInt(pointsTokens.nextToken());
					int points1 = Integer.parseInt(pointsTokens.nextToken());
					int points2 = Integer.parseInt(pointsTokens.nextToken());
					team1.points += points1;
					team2.points += points2;
					
					if (points1 > points2) {
						sets1Won++;
						sets2Lost++;
					} 
					
					if (points2 > points1) {
						sets2Won++;
						sets1Lost++;
					}
				}
				
				team1.sets += (sets1Won - sets1Lost);
				team2.sets += (sets2Won - sets2Lost);
				
				if (sets1Won > sets2Won) team1.wins++;
				if (sets2Won > sets1Won) team2.wins++;
				
			}
			
			Arrays.sort(array);
			
//			for (int k = 1; k < 50; k++) {
//				System.out.print(k % 10);
//			}
//			System.out.println();
			for (Team10933 k : array) 
				System.out.println(k);
			System.out.println();
			readLn();
		}
	}

	static String readLn() {
		String newLine = System.getProperty("line.separator");
		StringBuilder buffer = new StringBuilder();
		int car = -1;
		try {
			car = System.in.read();
			while ((car > 0) && (car != newLine.charAt(0))) {
				buffer.append((char) car);
				car = System.in.read();
			}
			if (car == newLine.charAt(0))
				System.in.skip(newLine.length() - 1);
		} catch (java.io.IOException e) {
			return (null);
		}
		if ((car < 0) && (buffer.length() == 0))
			return (null);
		return (buffer.toString());
	}
	
} 

class Team10933 implements Comparable<Team10933>{
	
	String name;

	int wins = 0;
	
	int sets = 0;
	
	int points = 0;
	
	@Override
	public int compareTo(Team10933 o) {
		if (wins != o.wins) {
			if (wins > o.wins) return -1;
			else return +1;
		}
		
		if (sets != o.sets) {
			if (sets > o.sets) return -1;
			else return +1;
		}
		
		if (points != o.points) {
			if (points > o.points) return -1;
			else return +1;
		}
		
		
		return name.compareTo(o.name);
	}
	
	
	public String toString() {
		String nameFormatted = getFormatted(name, 20);
		String winsFormatted = getFormatted(5, Integer.toString(wins));
		String setsFormatted = getFormatted(5, Integer.toString(sets));
		String pointsFormatted = getFormatted(10, Integer.toString(points));
		return nameFormatted + winsFormatted +  setsFormatted + pointsFormatted;
	}


	private String getFormatted(int i, String string) {
		StringBuilder sb = new StringBuilder();
		
		for (int k = string.length(); k < i; k++) {
			sb.append(' ');
		}
		
		sb.append(string);
		
		return sb.toString();
	}


	private String getFormatted(String string, int i) {
		StringBuilder sb = new StringBuilder(string);
		
		for (int k = string.length(); k < i; k++) {
			sb.append(' ');
		}
		
		return sb.toString();
	}
	
}
